package com.manor.main.http;

import com.ishumei.smantifraud.SmAntiFraud;
import com.manor.common.CommonAppConfig;
import com.manor.common.http.HttpClient;
import com.manor.common.http.JHttpCallback;
import com.manor.common.http.PitUtil;
import com.manor.common.utils.DeviceUtil;

import java.util.LinkedHashMap;

import okhttp3.MediaType;

public class JMainHttpUtil {
    public static final MediaType JSON = MediaType.parse("application/json;charset=utf-8");
    public static final MediaType MULTIPART = MediaType.parse("multipart/form-data;charset=utf-8");

    /**
     * 取消网络请求
     */
    public static void cancel(String tag) {
        HttpClient.getInstance().cancel(tag);
    }

    /**
     * 手机号 获取验证码
     */
    public static void JloginCode(String mobile, JHttpCallback callback) {
        LinkedHashMap<String, Object> map = new LinkedHashMap();
        map.put("mobile", mobile);
        HttpClient.getInstance().jPost("admin-sms/app/sms/v1/send/msg", MainHttpConsts.LOGIN)
                //.params("mobile", mobile)
                .upRequestBody(PitUtil.getSignBody(map))
                .execute(callback);
    }

    /**
     * 手机号 获取验证码
     */
    public static void getCode(String mobile, int type, JHttpCallback callback) {
        LinkedHashMap<String, Object> map = new LinkedHashMap();
        map.put("mobile", mobile);
        map.put("type", type);
        HttpClient.getInstance().jPost("admin-sms/app/sms/v1/send/msg", MainHttpConsts.CODE_TYPE)
                //.params("mobile", mobile)
                .upRequestBody(PitUtil.getSignBody(map))
                .execute(callback);
    }
    //    HttpParams  params = new HttpParams();
    //        params.put("user_login", phoneNum);
    //        params.put("code", code);
    //        params.put("type", 1);


    /**
     * 手机号 获取验证码
     * type 1.注册 2.短信登陆 3.忘记密码 4.H5注册
     */
    public static void getSmsCode(String mobile, int type, String rCode,JHttpCallback callback) {
        LinkedHashMap<String, Object> map = new LinkedHashMap();
        map.put("mobile", mobile);
        map.put("type", type);
        map.put("riskManagementToken", rCode);
        HttpClient.getInstance().jPost("admin-sms/app/sms/v1/send/msg", MainHttpConsts.CODE_TYPE)
                .upRequestBody(PitUtil.getSignBody(map))
                .execute(callback);
    }

    /**
     * 是否需要网易验证
     */
    public static void getIsWY( JHttpCallback callback) {
        LinkedHashMap<String, Object> map = new LinkedHashMap();

        HttpClient.getInstance().Jpost("admin-sms/app/sms/v1/is-verification", MainHttpConsts.GET_IS_WY)
                .upRequestBody(PitUtil.getBody(map))
                .execute(callback);
    }


    /**
     * 手机号 验证码登录
     */
    public static void login(String phoneNum, String code, int npcCode, JHttpCallback callback) {

        LinkedHashMap<String, Object> map = new LinkedHashMap();
        map.put("mobile", phoneNum);
        map.put("code", code);
        map.put("type", 1);
        map.put("npcCode", npcCode);
        map.put("devCode", DeviceUtil.getOnlyID());

        map.put("version", CommonAppConfig.APP_VERSION);
        map.put("model", CommonAppConfig.SYSTEM_MODEL);
        map.put("system", CommonAppConfig.SYSTEM_RELEASE);
        map.put("deviceId", SmAntiFraud.getDeviceId());

        HttpClient.getInstance().Jpost("admin-auth/app/sign/v1/identify", MainHttpConsts.LOGIN)
                //    .upString(String.valueOf(mGson.toJson(params)),JSON)
                .upRequestBody(PitUtil.getBody(map))
                .execute(callback);
    }

    /**
     * 手机号token登录--闪验
     */
    public static void tokenLogin(String token, String type, int npcCode, JHttpCallback callback) {
        LinkedHashMap<String, Object> map = new LinkedHashMap();
        map.put("token", token);
        map.put("type", 1);
        map.put("npcCode", npcCode);
        map.put("devCode", DeviceUtil.getOnlyID());

        map.put("version", CommonAppConfig.APP_VERSION);
        map.put("model", CommonAppConfig.SYSTEM_MODEL);
        map.put("system", CommonAppConfig.SYSTEM_RELEASE);
        map.put("deviceId", SmAntiFraud.getDeviceId());
        HttpClient.getInstance().Jpost("admin-auth/app/sign/v1/identify", MainHttpConsts.LOGIN)
                .upRequestBody(PitUtil.getBody(map))
                .execute(callback);
    }

    /**
     * 第一次登录更新信息
     *
     * @param uid
     * @param token
     * @param genderType 性别
     * @param date       日期
     * @param callback
     */
    public static void updateAvatar(String uid, String token, int genderType, String date, int npcCode, String code,
                                    JHttpCallback callback) {
        LinkedHashMap<String, Object> map = new LinkedHashMap();
        //  jsonObject.put("uid", CommonAppConfig.getInstance().getUid());
        //    jsonObject.put();
        map.put("sex", genderType + "");
        map.put("birthday", date);
        map.put("recommendUid", code);
        map.put("npcCode", npcCode);
        map.put("source", 1);
        HttpClient.getInstance().Jpost("admin-auth/app/user/v1/logon", MainHttpConsts.GET_FIRST_LOGIN)
                .upRequestBody(PitUtil.getBody(map))
                .execute(callback);
    }

    /**
     * 获取系统邀请码
     */
    public static void getInvitationCode(JHttpCallback callback) {
        LinkedHashMap<String, Object> map = new LinkedHashMap();

        HttpClient.getInstance().Jpost("admin-auth/app/sign/v1/apply-npc-code", MainHttpConsts.LOGIN)
                .upRequestBody(PitUtil.getBody(map))
                .execute(callback);
    }

    /**
     * 获取认证的随机金额
     * 废弃，我这萌新看不懂的骚操作，后台表示合并成一个接口{@link JMainHttpUtil#getNeedOrPay(String, JHttpCallback)}
     */
    @Deprecated
    public static void getAuthMoney(JHttpCallback callback) {
        LinkedHashMap<String, Object> map = new LinkedHashMap();

        HttpClient.getInstance().Jpost("admin-transfer/app/v1/face/random_price", MainHttpConsts.GET_AUTH_MONEY)
                .upRequestBody(PitUtil.getBody(map))
                .execute(callback);
    }

    /**
     * 支付认证的随机金额
     * 废弃，我这萌新看不懂的骚操作，后台表示合并成一个接口{@link JMainHttpUtil#getNeedOrPay(String, JHttpCallback)}
     */
    @Deprecated
    public static void payAuthMoney(JHttpCallback callback) {
        LinkedHashMap<String, Object> map = new LinkedHashMap();

        HttpClient.getInstance().Jpost("admin-transfer/app/v1/face/pay", MainHttpConsts.PAY_AUTH_MONEY)
                .upRequestBody(PitUtil.getBody(map))
                .execute(callback);
    }


    /**
     * 随机金额和付费
     *
     * @param type 1付费，0获取
     */
    public static void getNeedOrPay(String type, JHttpCallback callback) {
        LinkedHashMap<String, Object> map = new LinkedHashMap();
        map.put("type", type);

        HttpClient.getInstance().Jpost("admin-transfer/app/face/v1/random-price", MainHttpConsts.PAY_AUTH_MONEY)
                .upRequestBody(PitUtil.getBody(map))
                .execute(callback);
    }

    /**
     * 搜索人脸
     *
     * @param type 类型 1.扫脸支付 2.登录扫脸
     */
    public static void getFaceSearch(String type, JHttpCallback callback) {
        LinkedHashMap<String, Object> map = new LinkedHashMap();
        map.put("type", type);
        map.put("devCode", DeviceUtil.getOnlyID());

        HttpClient.getInstance().Jpost("admin-face/app/face/v1/search-face", MainHttpConsts.SEARCH_FACE)
                .upRequestBody(PitUtil.getBody(map))
                .execute(callback);
    }


    /**
     * 查询嗨券记录
     */
    public static void getCouponsList(int current, JHttpCallback callback) {
        LinkedHashMap<String, Object> map = new LinkedHashMap();
        map.put("current", current);
        map.put("size", 20);
        map.put("uid", CommonAppConfig.getInstance().getUid());
        HttpClient.getInstance().Jpost("admin-php/app/sd-coupons/v1/get-sd-coupons-record", MainHttpConsts.LOGIN)
                .upRequestBody(PitUtil.getBody(map))
                .execute(callback);
    }

    /**
     * 使用账号密码登录
     *
     * @param phone    手机号
     * @param password 密码
     */
    public static void loginByPassword(String phone, String password, int npcCode, JHttpCallback callback) {
        LinkedHashMap<String, Object> map = new LinkedHashMap();
        map.put("mobile", phone);
        map.put("password", password);
        map.put("type", 1);
        map.put("npcCode", npcCode);
        map.put("devCode", DeviceUtil.getOnlyID());
        map.put("version", CommonAppConfig.APP_VERSION);
        map.put("model", CommonAppConfig.SYSTEM_MODEL);
        map.put("system", CommonAppConfig.SYSTEM_RELEASE);
        map.put("deviceId", SmAntiFraud.getDeviceId());

        HttpClient.getInstance().Jpost("admin-auth/app/sign/v1/login", MainHttpConsts.LOGIN_BY_PASSWORD)
                .upRequestBody(PitUtil.getBody(map))
                .execute(callback);
    }

    /**
     * 重置密码
     *
     * @param phone    手机号
     * @param password 密码
     */
    public static void resetPassword(String phone, String password, String code, JHttpCallback callback) {
        LinkedHashMap<String, Object> map = new LinkedHashMap();
        map.put("mobile", phone);
        map.put("password", password);
        map.put("code", code);
        HttpClient.getInstance().Jpost("admin-auth/app/sign/v1/setPassWord", MainHttpConsts.RESET_PASSWORD)
                .upRequestBody(PitUtil.getBody(map))
                .execute(callback);
    }

    /**
     * 账号密码注册
     *
     * @param phone    手机号
     * @param password 密码
     */
    public static void register(String phone, String password, String code,int npcCode, String inviteCode,
                                JHttpCallback callback) {
        LinkedHashMap<String, Object> map = new LinkedHashMap();
        map.put("mobile", phone);
        map.put("password", password);
        map.put("code", code);
        map.put("npcCode", npcCode);
        map.put("recommendUid", inviteCode);
        map.put("source", 1);
        map.put("devCode", DeviceUtil.getOnlyID());
        map.put("version", CommonAppConfig.APP_VERSION);
        map.put("model", CommonAppConfig.SYSTEM_MODEL);
        map.put("system", CommonAppConfig.SYSTEM_RELEASE);
        map.put("deviceId", SmAntiFraud.getDeviceId());
        HttpClient.getInstance().Jpost("admin-auth/app/sign/v1/register", MainHttpConsts.RESET_PASSWORD)
                .upRequestBody(PitUtil.getBody(map))
                .execute(callback);
    }

    /**
     * 短信登录
     *
     * @param phone 手机号
     * @param code  密码
     */
    public static void loginByMsg(String phone, String code, int npcCode, JHttpCallback callback) {
        LinkedHashMap<String, Object> map = new LinkedHashMap();
        map.put("mobile", phone);

        map.put("code", code);
        map.put("type", 1);
        map.put("npcCode", npcCode);
        map.put("devCode", DeviceUtil.getOnlyID());

        map.put("version", CommonAppConfig.APP_VERSION);
        map.put("model", CommonAppConfig.SYSTEM_MODEL);
        map.put("system", CommonAppConfig.SYSTEM_RELEASE);
        map.put("deviceId", SmAntiFraud.getDeviceId());

        HttpClient.getInstance().Jpost("admin-auth/app/sign/v1/smsLogin", MainHttpConsts.RESET_PASSWORD)
                .upRequestBody(PitUtil.getBody(map))
                .execute(callback);
    }


}
